package com.demo.function.office.excel;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.demo.model.Order;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileOutputStream;
import java.util.Date;
import java.util.List;

@Slf4j
public class ExcelFunction {

    public void genExcel() {
        Order order = new Order();
        order.setDateOfPurchase(new Date());

        List<Order> list = Lists.newArrayList(order);

        try (FileOutputStream fos = new FileOutputStream("d:/export.xls");
             Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), Order.class, list)){

            workbook.write(fos);
        } catch (Exception e) {
            log.error("", e);
        }
    }
}
